//
//  IDViewController.m
//  soccer
//
//  Created by 上官千城 on 15/9/3.
//  Copyright (c) 2015年 上官千城. All rights reserved.
//

#import "IDViewController.h"
#import "QRMethod.h"
@interface IDViewController ()

@end

@implementation IDViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
  
  //更改ID
    if (self.type == 1) {
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"保存" style:UIBarButtonItemStyleDone target:self action:@selector(saveButton)];
        [self creatType1];
    }
    //更改昵称
    if (self.type == 2) {
        [self creatType2];
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"保存" style:UIBarButtonItemStyleDone target:self action:@selector(saveButton)];
    }
    //二维码
    if (self.type == 3) {
        self.view.backgroundColor = [UIColor whiteColor];
        [self creatType3];
    }
    //地域
    if (self.type == 4) {
        [self creatType4];
    }
    //签名
    if (self.type == 5) {
        [self creatType5];
         self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"保存" style:UIBarButtonItemStyleDone target:self action:@selector(saveButton)];
    }
    
}
//保存按钮
-(void)saveButton
{
    if (self.type == 2) {
//        UIAlertView *aler = [[UIAlertView alloc]initWithTitle:@"提示" message:@"确认更改昵称" delegate:self cancelButtonTitle:@"是" otherButtonTitles:@"否", nil];
//        [aler show];
        //        aler.tag = 10001;
        [self.nickDelegate bringNickname:self.Nickname.text];
        [self.navigationController popViewControllerAnimated:YES];
    }
}

//alertView协议方法
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{

}

//返回
-(void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
}
//更改ID
-(void)creatType1
{
    UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(10, 90, WIDTH-20, 40)];
    text.borderStyle = UITextBorderStyleRoundedRect;
    text.placeholder = @"请输入ID";
    text.clearButtonMode = UITextFieldViewModeAlways;
    [self.view addSubview:text];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(text.frame.origin.x, text.frame.origin.y+text.frame.size.height+5, WIDTH, 20)];
    label.text = @"ID是个人身份的象征,用户不可频繁更改!";
    [self.view addSubview:label];
    
}
//更改昵称
-(void)creatType2
{
    self.Nickname = [[UITextField alloc]initWithFrame:CGRectMake(10, 90, WIDTH-20, 40)];
    self.Nickname.borderStyle = UITextBorderStyleRoundedRect;
    self.Nickname.placeholder = @"请输入昵称";
    self.Nickname.clearButtonMode = UITextFieldViewModeAlways;
    [self.view addSubview:self.Nickname];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(self.Nickname.frame.origin.x, self.Nickname.frame.origin.y+self.Nickname.frame.size.height+5, WIDTH, 20)];
    label.text = @"起个响亮的名字让别人注意你";
    [self.view addSubview:label];
    
}
//二维码
-(void)creatType3
{//生成二维码
    UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(WIDTH / 5, 100 , WIDTH/5 *3, WIDTH/5 * 3)];
//    image.backgroundColor = [UIColor brownColor];
//    image.image = [UIImage imageNamed:@"扫一扫二维码@2x"];
//
    QRMethod *qr = [[ QRMethod alloc]init];
    UIImage *qrcode = [qr createNonInterpolatedUIImageFormCIImage:[qr createQRForString:@"http://23a501249.atobo.com.cn/"] withSize:250.0f];
    UIImage *customQrcode = [qr imageBlackToTransparent:qrcode withRed:60.0f andGreen:74.0f andBlue:89.0f];
    image.image = customQrcode;
    // set shadow
    image.layer.shadowOffset = CGSizeMake(0, 2);
    image.layer.shadowRadius = 2;
    image.layer.shadowColor = [UIColor blackColor].CGColor;
    image.layer.shadowOpacity = 0.5;
    [self.view addSubview:image];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, image.frame.origin.y + image.frame.size.height + 20, WIDTH, 20)];
    label.text = @"扫一扫上面的二维码,快点加我吧";
    label.textColor = [UIColor whiteColor];
    label.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:label];
}
//地域
-(void)creatType4
{
    
}
//编辑签名
-(void)creatType5
{
    UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(10, 80, WIDTH - 20, 150)];
    text.placeholder = @"此处可以输出100字";
    text.borderStyle = UITextBorderStyleRoundedRect;
    [self.view addSubview:text];
    //signature签名
    UIButton *changeSignature = [UIButton buttonWithType:UIButtonTypeCustom];
    changeSignature.frame = CGRectMake(WIDTH-70, text.frame.origin.y + text.frame.size.height + 20, 80, 30);
    [changeSignature setTitle:@"确认修改" forState:UIControlStateNormal];
    [changeSignature setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [changeSignature addTarget:self action:@selector(changeSignature) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:changeSignature];
}

-(void)changeSignature
{
    NSLog(@"确认签名");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
